package com.java.control.impl;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;

import com.java.common.SessionInfo;
import com.java.control.AbstractAdminCommandController;
import com.java.control.search.CodeSearchCond;
import com.java.control.search.OrderSearchCond;
import com.java.control.search.SearchStat;
import com.java.control.search.UserSearchCond;
import com.java.entity.Code;
import com.java.entity.OrderForm;
import com.java.entity.User;
import com.java.mis.UserType;
import com.java.service.CodeService;
import com.java.service.OrderService;
import com.java.service.UserService;

/**
 * 人员管理
 * @author wqf
 * @version  Nov 24, 2011 12:00:53 PM
 */
public class OrderListController extends AbstractAdminCommandController {

	public OrderListController(){
		this.setCommandClass(OrderSearchCond.class);
	}	

	protected ModelAndView executeRequest(HttpServletRequest request,HttpServletResponse response,Object command)
		throws Exception{
		
		OrderSearchCond searchCond = (OrderSearchCond)command;
		
		ModelAndView mav=new ModelAndView(this.view);
		searchCond.setPageSize(10L);
		
		SessionInfo user = getSessionInfo(request);
		if(null!=user){
			if(user.getUserType()==UserType.admin){
				
			}else{
				searchCond.setUserId(user.getUserId());
			}
		}
		
		SearchStat searchStat = this.orderService.getSearchStat(OrderForm.class, searchCond);
		List<OrderForm> list = this.orderService.search(OrderForm.class,searchCond);
		mav.addObject("searchStat", searchStat);
		mav.addObject("searchCond", searchCond);
		mav.addObject("orderList", list);		
				
		//用户信息
		UserSearchCond userSearchCond = new UserSearchCond();
//		userSearchCond.setIsAdmin(false);//允许管理添加订单
		userSearchCond.setStatus(true);
		List<User> userList = this.userService.search(User.class,userSearchCond);
		mav.addObject("userList", userList);
		
		//国家
		CodeSearchCond countrySearchCond = new CodeSearchCond();
		countrySearchCond.setCodeType("国家");
		List<Code> countryList = this.codeService.search(Code.class,countrySearchCond);
		mav.addObject("countryList", countryList);
		
		return mav;
		
	}
		
	public void setOrderService(OrderService orderService) {
		this.orderService = orderService;
	}

	private String view;
	private OrderService orderService;
	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	private UserService userService;
	
	public void setView(String view) {
		this.view = view;
	}

	public void setCodeService(CodeService codeService) {
		this.codeService = codeService;
	}

	private CodeService codeService;
	
}
